package com.shbaiche.bifenba.ui.my;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import cn.droidlover.xdroid.base.XActivity;

import com.allen.library.SuperTextView;
import com.google.gson.Gson;
import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.model.Event;
import com.shbaiche.bifenba.model.base.TransMessage;
import com.shbaiche.bifenba.model.user.AboutMessage;
import com.shbaiche.bifenba.model.video.ArticleDetailMessage;
import com.shbaiche.bifenba.net.JsonCallback;
import com.shbaiche.bifenba.net.NetApi;
import com.shbaiche.bifenba.ui.base.BaseActivity;
import com.shbaiche.bifenba.ui.base.WebActivity;
import com.shbaiche.bifenba.util.StringUtil;
import com.shbaiche.bifenba.util.ToastUtil;

import cn.droidlover.xdroid.event.BusFactory;
import cn.droidlover.xdroidbase.router.Router;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import okhttp3.Call;


/**
 * Created by wanglei on 2016/12/9.
 */

public class AboutActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tv_info)
    TextView content;
    @BindView(R.id.about_stv_weixin)
    SuperTextView wx;
    @BindView(R.id.about_stv_site)
    SuperTextView site;
    @BindView(R.id.about_stv_tel)
    SuperTextView tel;
    @BindView(R.id.about_stv_email)
    SuperTextView email;
    @BindView(R.id.about_stv_address)
    SuperTextView add;
    Dialog dg;

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }


    @Override
    public void initData(Bundle savedInstanceState) {

        dg = new Dialog(this);
        dg.setContentView(R.layout.view_loading);

        NetApi.About(new AboutMessage(), new JsonCallback<TransMessage>() {

            @Override
            public void onFail(Call call, Exception e, int id) {
                dg.hide();
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                ToastUtil.show("onFail" + e.getMessage());
                dg.hide();
            }

            @Override
            public void onResponse(TransMessage response, int id) {
                dg.hide();
                Gson gson = new Gson();
                AboutMessage msg = gson.fromJson(response.getMessage(), AboutMessage.class);

                if (StringUtil.equalsIgnoreCase(TransMessage.SuccessCode, msg.getCode())) {
                    content.setText(msg.getProfile() + "");
                    wx.setRightString(msg.getWx() + "");
                    site.setRightString(msg.getWebsite() + "");
                    tel.setRightString(msg.getHotline() + "");
                    email.setRightString(msg.getEmail() + "");
                    add.setRightString(msg.getAddress() + "");
                } else {
                }
            }
        });
    }

    @Override
    public void setListener() {

    }


    public static void launch(Activity activity) {
        Router.newIntent()
                .from(activity)
                .to(AboutActivity.class)
                .data(new Bundle())
                .launch();
    }

    @Override
    protected void onDestroy() {
        if (dg != null) {
            dg.dismiss();
            dg = null;
        }
        super.onDestroy();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_about;
    }

    @Override
    public void setToolbar() {
        initToolbar(toolbar, "关于我们");
    }
}
